<?php
if(!defined('IN_DISCUZ')) exit('Access Denied');
header('Content-Type: application/json');

global $_G;
// $uid = $_G['uid'];
// if(!$uid) {
//     $data = [
//         'success' => false,
//         'message' => '请先登录'
//     ];
//     echo json_encode($data);
//     exit;
// }

if(!submitcheck('formhash')) {
    $data = [
        'success' => false,
        'message' => '请求来源验证失败'
    ];
    echo json_encode($data);
    exit;
}

$er_name = isset($_GET['er_name']) ? trim($_GET['er_name']) : '';
// 映射
$allowed_er_names = [
    'upload' => 'upload.php',
    'delete' => 'delete.php',
];

if(empty($er_name) || !isset($allowed_er_names[$er_name])) {
    $data = [
        'success' => false,
        'message' => '无效的请求'
    ];
    echo json_encode($data);
    exit;
}

// 加载对应的API文件
$api_file = dirname(__FILE__) . '/api/' . $allowed_er_names[$er_name];
if(file_exists($api_file)) {
    require_once $api_file;
} else {
    $data = [
        'success' => false,
        'message' => 'API文件不存在'
    ];
    echo json_encode($data);
    exit;
}